package 堆.练习;

import java.util.PriorityQueue;

//从小到大第k个数
public class Text_2 {
    public int  maxK(int[] array,int k){
        if(k<=0||array==null){
            return -1;
        }
        int ret = 0;
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i = 0; i < array.length; i++) {
            queue.offer(array[i]);
        }
        while(k>0){
            ret = queue.poll();
            k--;
        }
        return ret;
    }

    public static void main(String[] args) {
        Text_2 text2 = new Text_2();
        int[] array = {1,5,9,3,5,4};
        int x = text2.maxK(array,3);
        System.out.println(x);
    }
}
